package Feb_15;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class FileServer {
    public static void main(String[] args) {
        try {
            //启动服务
            ServerSocket serverSocket = new ServerSocket(8080);
            //接受客户端产生套接字
            Socket socket = serverSocket.accept();
            InputStream inputStream = socket.getInputStream();
            FileOutputStream fileOutputStream = new FileOutputStream(new File("src/Feb_15/File2.txt"));
            System.out.println("接受文件:"+socket.getInetAddress().getHostAddress());

            byte[] bytes = new byte[1024];
            int len;
            while ((len=inputStream.read(bytes))!=-1){
                fileOutputStream.write(bytes,0,len);
            }

            OutputStream outputStream = socket.getOutputStream();
            outputStream.write("已接受".getBytes());
            socket.shutdownOutput();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
